package com.group.eams.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.group.eams.pojo.dto.PermissionQueryDto;
import com.group.eams.pojo.entity.Permission;
import com.group.eams.pojo.vo.PermissionListVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

/**
* @author 恩哲欣
* @description 针对表【permission(权限表)】的数据库操作Mapper
* @createDate 2024-10-29 16:09:34
* @Entity com.group.eams.pojo.entity.Permission
*/
public interface PermissionMapper extends BaseMapper<Permission> {

    /**
     * 分页查询权限列表
     * @param page
     * @param permissionQueryDto
     * @return
     */
    Page<PermissionListVo> findPermissionByQueryDto(Page page
                            ,@Param("permissionQueryDto")PermissionQueryDto permissionQueryDto);


    /**
     * 根据角色id查询对应的权限
     * @param roleId
     * @return
     */
    @Select("SELECT p.id,p.module_name,p.table_name,p.permission_name,p.tag,p.remark,p.created FROM role_permission rp, permission p " +
            " WHERE rp.permission_id = p.id AND rp.role_id =#{roleId}")
    List<Permission> findPermissionIdRoleId(Long roleId);

    /**
     * 根据用户id查询对应的权限
     * @param userId
     * @return
     */
    @Select("select distinct p.id,p.permission_name,p.tag,p.created from user u,role_permission rp,permission p \n" +
            "where u.role_id=rp.role_id and rp.permission_id=p.id and u.id=#{userId}")
    List<Permission> findPermissionByUserId(Long userId);
}
